﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ProjectWizardManagementv1.Infrastructure.Static
{
    public static class MyDirectory
    {
        public static IEnumerable<string> EnumerateFilesAndDirectories(string path)
        {
            IEnumerable<string> directoryInfo = new List<string>();
            try
            {
               directoryInfo = Directory.EnumerateFiles(path).Union(Directory.EnumerateDirectories(path)).OrderBy(d => d);
               
            }
            catch(IOException)
            {
                
            }
            return directoryInfo;

        }

        public static void FullDelete(string path)
        {
            var files = Directory.GetFiles(path);
            var directories = Directory.GetDirectories(path);

            foreach (var file in files)
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }

            foreach (var directory in directories)
                FullDelete(directory);

            try
            {
                Directory.Delete(path);    
            }
            catch(IOException)
            {
            }
        }
    }
}
